<?php
		
if($_GET['action']=='home'){
	direct_url();
		$db=new db;
		$db->connect();

			
			
		$db->query("select id,views,likes,comments from index_post where is_text=1 and pick=1 order by id desc limit 0,4");
		$dt=$db->fetchAll();
		foreach($dt as $row){
			$data['pick'][]=get_post($row['id']);
		}
		$db->close();
		
	$cache=new Cache;
	$sql ="select * from index_post where is_text=1  order by id desc";
	$sql2="select id from index_post where is_text=1";
	//$url=HOME."index.php?module=news&act=type&type=blog&action=home&page=";
	$url=HOME."blog/";
	$pager = new Pagination($sql,15,6,$url,500,"post");
	$pager->setDebug(false);
	$data[info] = $pager->paginate($cache,$sql2);
	$data[nav]	= $pager->renderFullNav();
	$data['page']=$pager->get_num_page();
			
			$data1[title]=web_title('Chuyên Mục Blog | Mong.vn');
			$data1[mota]=web_des('Chuyên Mục Blog , chia sẻ bài viết chủ đề hữu ích trên Mong.vn');
			$data1['keyword']=web_keyword("blog,xem bai viet,chia se bai viet,mong.vn");
			loadview('template/header',$data1);
			loadview("news/list_news_blog",$data);
} // End action home

if($_GET['action']=='category'){
	direct_url();
	$data['category']=cache_get_category(intval($_GET['id']));
	$cache=new Cache;
	$sql ="select * from index_post where is_text=1 and cat_id=".intval($_GET['id'])."  order by id desc";
	$sql2="select id from index_post where is_text=1 and cat_id=".intval($_GET['id']);
	//$url=HOME."index.php?module=news&act=type&type=blog&action=category&id=".intval($_GET['id'])."&page=";
	$url=HOME.'blog/c'.intval($_GET['id']).'/'.$data['category']['alias'].'/';
	$pager = new Pagination($sql,15,6,$url,500,"post");
	$pager->setDebug(false);
	$data[info] = $pager->paginate($cache,$sql2);
	$data[nav]	= $pager->renderFullNav();
	
			
			$data1[title]=web_title($data['category']['seo_title']);
			$data1['keyword']=web_keyword($data['category']['seo_keyword']);
			$data['mota']=web_des($data['category']['seo_description']);
			loadview('template/header',$data1);
			loadview("news/list_news_blog_category",$data);
} // End of action category
			
			
if($_GET['action']=='subcategory'){
	direct_url();
	$data['subcategory']=cache_get_category(intval($_GET['id']));
	$data['category']=cache_get_category($data['subcategory']['p_id']);
	
	$cache=new Cache;
	$sql ="select * from index_post where is_text=1 and sub_id=".intval($_GET['id'])."  order by id desc";
	$sql2="select id from index_post where is_text=1 and sub_id=".intval($_GET['id']);
	//$url=HOME."index.php?module=news&act=type&type=blog&action=subcategory&id=".intval($_GET['id'])."&page=";
	$url=HOME.'blog/s'.intval($_GET['id']).'/'.$data['subcategory']['alias'].'/';
	$pager = new Pagination($sql,10,6,$url,500,"post");
	$pager->setDebug(false);
	$data[info] = $pager->paginate($cache,$sql2);
	$data[nav]	= $pager->renderFullNav();
	
			
			$data1[title]=web_title($data['subcategory']['seo_title']);
			$data1['keyword']=web_keyword($data['subcategory']['seo_keyword']);
			$data['mota']=web_des($data['subcategory']['seo_description']);
			loadview('template/header',$data1);
			loadview("news/list_news_blog_subcategory",$data);
} // End of action subcategory
if($_GET['action']=='user'){
	direct_url();
	$db=new db;
	$db->connect();
	
	$cache=new Cache;
	$sql ="select * from index_post where is_text=1 and username='".mysql_real_escape_string($_GET['id'])."'  order by id desc";

	$sql2="select id from index_post where is_text=1 and username='".mysql_real_escape_string($_GET['id'])."'";
	$db->close();
	//$url=HOME."index.php?module=news&act=type&type=blog&action=subcategory&id=".intval($_GET['id'])."&page=";
	$url=HOME.'blog/user/'.$_GET['id'].'/';
	$pager = new Pagination($sql,10,6,$url,500,"post");
	$pager->setDebug(false);
	$data[info] = $pager->paginate($cache,$sql2);
	$data[nav]	= $pager->renderFullNav();
	
			
			$data1[title]=web_title('Blog của '.$_GET['id']);
			$data1[mota]=web_des('Blog của '.$_GET['id']);
			$data1[keyword]=web_keyword('Blog,bai viet,chu de,bai dang, '.$_GET['id']);
			loadview('template/header',$data1);
			loadview("news/list_news_blog_user",$data);
} // End of action user
if($_GET['action']=='playlist'){
direct_url();
	$data['album']=cache_get_album(intval($_GET['id']));
	$db=new db;
	$db->connect();
	$cache=new Cache;
	$sql ="select * from index_post where is_text=1 and album_id= ".intval($_GET['id'])."  order by id desc";
	$sql2="select id from index_post where is_text=1 and album_id=".intval($_GET['id'])."";
	$db->close();
	$url=HOME."blog/playlist/".$_GET['id'].'.html/';
	$pager = new Pagination($sql,10,6,$url,0,"post");
	$pager->setDebug(false);
	$data[info] = $pager->paginate($cache,$sql2);
	$data[nav]	= $pager->renderFullNav();
	
			
			$data1[title]=web_title($data['album']['name']);
			if($data['album']['title']==""){
				$data1[title]=web_title($data['album']['name']);
			}else{
				$data1[title]=web_title($data['album']['title']);
			}
			if($data['album']['keyword']==""){
				$data1[keyword]=$data['album']['name'].','.khongdau($data['album']['name']);
			}else{
				$data1[keyword]=$data['album']['keyword'];
			}
			
			if($data['album']['description']==""){
				$data1[mota]=$data['album']['name'];
			}else{
				$data1[mota]=$data['album']['description'];
			}
			
			loadview('template/header',$data1);
			loadview("news/list_news_blog_album",$data);
} // End of action user